#!/usr/bin/env bash
. ./scripts/devcontainer/_assert-in-container "$0" "$@"

set -euo pipefail

if [[ "$#" -eq 1 ]]; then
  echo "shellcheck $1"
  shellcheck -x -e SC2002 -e SC2044 -e SC2086 "$1"
else
  echo "shellcheck bash files ..."
  # In the scripts/ directory,
  # everything with a shebang containing sh (bash, sh)
  #
  # SC2044: https://github.com/koalaman/shellcheck/wiki/SC2044
  # SC2086: https://github.com/koalaman/shellcheck/wiki/SC2086
  # shellcheck disable=SC2038
  find ./* \
    -path ".git" -prune \
    -o -path "backend/static" \
    -o -path "./backend/static" \
    -o -path "rundir" -prune \
    -o -path "./rundir" -prune \
    -o -path "backend/paket-files" -prune \
    -o -path "./backend/paket-files" -prune \
    -o -path "backend/Build" -prune \
    -o -path "./backend/Build" -prune \
    -o -type f \
    -exec awk 'FNR == 1 && /^#!.*sh/{print FILENAME}' {} + \
    | xargs shellcheck -e SC2002 -e SC2044 -e SC2086
fi





